package org.example.cho8.mapper;

import org.apache.ibatis.annotations.*;
import org.example.cho8.entity.User;

/**
 * ClassName: UserMapper
 * Description:
 *
 * @Author zjl
 * @Create 2025/04/25 10:19
 * @Version 1.0
 */
public interface UserMapper {

    @Insert("insert into stu_info(s_name, s_age) values(#{name},#{age})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(User user);

    @Update("update stu_info set s_name=#{name}, s_age=#{age} where s_id=#{id}")
    void update(User user);

    @Delete("delete from stu_info where s_id=#{id}")
    void delete(Integer id);

    @Select("select s_id as id, s_name as name, s_age as age from stu_info where s_id = #{id}")
    //@ResultType(User.class)
    //使用@ResultMap时，value的值是namespace + resultMap的id
    @ResultMap("org.example.cho8.mapper.UserMapper.userMap")
    User getUserById(Integer id);
}
